using FluentValidation;
using MediatR;

namespace Wips.AppService.Authorities.Permissions.Requests;

/// <summary>
/// 新增，不带事务性
/// </summary>
public class AddPermissionRequest : IRequest<bool>
{
    /// <summary>
    /// 角色Id
    /// </summary>
    public string? RoleId { get; set; }


    /// <summary>
    /// 应用id
    /// </summary>
    public string ApplicationId { get; set; } = "";

    /// <summary>
    /// 菜单Ids
    /// </summary>
    public IList<string?>? MenuIds { get; set; } = new List<string?>();

    /// <summary>
    /// 操作Ids
    /// </summary>
    public IList<string?>? OperationIds { get; set; } = new List<string?>();
}

/// <summary>
/// 
/// </summary>
public class AddPermissionRequestValidator : AbstractValidator<AddPermissionRequest>
{
    /// <summary>
    /// 
    /// </summary>
    public AddPermissionRequestValidator()
    {
        RuleFor(p => p.RoleId)
            .Must(id => !string.IsNullOrEmpty(id))
            .WithMessage("角色不能为空");

        RuleFor(p => p.ApplicationId)
            .Must(id => !string.IsNullOrEmpty(id))
            .WithMessage("应用不能为空");

        RuleFor(p => p.MenuIds)
            .Must(ids => ids != null)
            .WithMessage("菜单不能为null");

        RuleFor(p => p.OperationIds)
            .Must(ids => ids != null)
            .WithMessage("操作不能为null");
    }
}